
#ifndef __FILEIO_H__
#define __FILEIO_H__

class osFILE {
public:
   virtual int          Read                    (void * buf, int count, int elemSize = 1) = 0;
   virtual int          Write                   (void * buf, int count, int elemSize = 1) = 0;

   virtual void         Flush                   (void) = 0;

   virtual bool         IsWritable              (void) const = 0;
};

class osFILE_DISK : public osFILE {
public:
                        osFILE_DISK             (void);
   virtual              ~osFILE_DISK            (void);

   bool                 OpenRead                (const char * filename, int bufferSize = 4096);
   bool                 OpenWrite               (const char * filename, int bufferSize = 4096);
   bool                 OpenAppend              (const char * filename, int bufferSize = 4096);
   void                 Close                   (void);

   int                  GetFilesize             (void) const;

   virtual int          Read                    (void * buf, int count, int elemSize = 1);
   virtual int          Write                   (void * buf, int count, int elemSize = 1);

   virtual void         Flush                   (void);

   virtual bool         IsWritable              (void) const { return isWritable; }

private:
   void                 AllocateBuffer          (int size);

private:
   BYTE *               buffer;
   BYTE *               bufferCur;
   int                  allocated;
   int                  bufferAvail;

   int                  offset;

   void *               handle;

   bool                 isWritable;
};

#endif // __FILEIO_H__